<template>
	<div class="home">
		<webview
			v-if="store.param.src"
			id="webview"
			allowpopups
			allowfullscreen
			webpreferences="contextIsolation=yes,nodeintegration=no"
			:src="store.param.src"
			@did-fail-load="handle_fail_load"
			@did-finish-load="handle_finish_load">
		</webview>
	</div>
</template>

<script setup>
	// import { Events } from "@/utils/events_bus/index.js";
	// import { ref, onMounted } from "vue";
	import { my_message } from "@/utils/my_message/index.js";
	import { useIndexStore } from "@/store/model";

	const msg = my_message();
	const store = useIndexStore()

	const handle_fail_load = event => {
		// 错误代码参考：
		// -3: ERR_ABORTED (用户取消加载)
		// -102: ERR_CONNECTION_REFUSED
		// -105: ERR_NAME_NOT_RESOLVED (DNS 失败)
		// -106: ERR_INTERNET_DISCONNECTED
		if (event.errorCode !== -3) {
			// 忽略用户主动取消的情况
			msg.msg_error("加载失败！");
			// Events.IPC.Renderer.send("close-window");
		}
	};
</script>

<style lang="less" scoped>
	.home {
		width: 100%;
		height: 100%;
		#webview {
			width: 100%;
			height: 100%;
		}
	}
</style>
